<template>
  <view class="content">
    <view class="status_bar"></view>

    <view class="topWrap">
      <image
        src="../../static/jiantous.png"
        class="arrow"
        @click="handleBack()"
      ></image>
      <view class="text">我的藏品</view>
      <view class="right" @click="toRecord()" v-if="!is_Merchant">兑换记录</view>
    </view>

    <view class="main_bottom" v-if="!is_Merchant">
      <view class="main_item" @click="handleSort(0)">
        <view
          class="main_item_text"
          :class="now_check == 0 ? 'main_item_active' : ''"
          >元创藏品</view
        >
      </view>

      <view class="main_item" @click="handleSort(1)">
        <view
          class="main_item_text"
          :class="now_check == 1 ? 'main_item_active' : ''"
          >甄猫藏品</view
        >
      </view>
    </view>

    <view class="have" v-if="now_check == 1">
      <view class="have_left">
        <text>拥有数量：</text>
        <text class="highlight">{{ detail.total }}</text>
      </view>
      <view class="have_right" @click="toExchange">兑换积分</view>
    </view>

    <view class="record_wrapper">
      <view class="record" v-for="(item, index) in productList">
        <image
          v-if="now_check == 0"
          class="record_image"
          :src="item.cover"
        ></image>
        <image
          v-else-if="now_check == 1"
          class="record_image"
          :src="item.product.cover"
        ></image>

        <view class="record_content">
          <view class="record_content_title">
            <text v-if="now_check == 0">{{ item.name }}</text>
            <text v-else-if="now_check == 1">{{ item.product.name }}</text>
          </view>

          <view class="record_content_CollectionCode">
            <image
              class="record_content_CollectionIcon"
              src="../../static/collect_icon.png"
            ></image>

            <text class="record_content_no">{{ item.no }}</text>
          </view>

          <view class="record_content_second">
            <image
              v-if="now_check == 0"
              class="record_content_avatar"
              :src="item.creator_avatar"
            ></image>
            <image
              v-else-if="now_check == 1"
              class="record_content_avatar"
              :src="item.product.creator_avatar"
            ></image>

            <view class="record_content_username">
              <text v-if="now_check == 0">{{ item.creator_name }}</text>
              <text v-else-if="now_check == 1">{{
                item.product.creator_name
              }}</text>
            </view>

            <view class="integral" v-if="now_check == 1"
              >{{
                item.product.zm_config
                  ? item.product.zm_config.exchange_rate
                  : 0
              }}
              积分</view
            >
          </view>
        </view>
      </view>

      <empty :show="productList.length == 0 && is_done"></empty>
    </view>
  </view>
</template>

<script>
import api from "../../api/api";
import tip from "@/utils/tip.js";
export default {
  data() {
    return {
      page: 1,
      productList: [],
      is_done: false,
      detail: {},
      now_check: 0,
      limit: 10,
      page: 1,
      is_Merchant: false,
    };
  },
  onLoad(options) {},
  onShow() {
    if (uni.getStorageSync("unique_code")) {
      this.is_Merchant = true;
    }
    this.now_check = 0;
    this.getProduct(true);
    // this.getList(true);
  },
  // 页面的触底事件
  onReachBottom() {
    this.page++;
    if (this.now_check == 0) {
      this.$u.throttle(this.getProduct(), 1000, true);
    } else if (this.now_check == 1) {
      this.$u.throttle(this.getList(), 1000, true);
    }
  },
  methods: {
    handleSort(index) {
      this.now_check = index;
      this.productList = [];
      if (index == 0) {
        this.getProduct(true);
      } else if (index == 1) {
        this.getList(true);
      }
    },
    handleBack() {
      uni.navigateBack({
        delta: 1,
      });
    },
    toRecord() {
      uni.navigateTo({
        url: `../zhenmao/zhenmao_record`,
      });
    },
    toExchange() {
      uni.navigateTo({
        url: `../zhenmao/zhenmao_exchange`,
      });
    },

    async getProduct(refresh) {
      if (refresh) {
        this.page = 1;
      }
      let userInfo = uni.getStorageSync("userInfo");
      let res = await api.stackingProducts({
        query: {
          user_id: userInfo.id,
          product_category: this.labelid,
          limit: this.limit,
          page: this.page,
        },
        loading: "加载中",
      });
      if (res.code === 0) {
        this.is_done = true;
        this.detail = res.data;
        if (refresh) {
          this.productList = res.data;
        } else {
          this.productList = this.productList.concat(res.data);
        }
      } else {
        tip.defaults(res.msg);
      }
    },

    async getList(refresh) {
      if (refresh) {
        this.page = 1;
      }
      let res = await api.zm_wallet({
        method: "get",
        query: {
          page: this.page,
          limit: this.limit,
        },
        loading: "加载中",
      });
      if (res.code === 0) {
        this.is_done = true;
        this.detail = res.data;
        if (refresh) {
          this.productList = res.data.data;
        } else {
          this.productList = this.productList.concat(res.data.data);
        }
      } else {
        tip.defaults(res.msg);
      }
    },
  },
};
</script>

<style lang="scss" scoped>
@import "../../style/yuanchuang.scss";
.content {
  width: 100%;
  height: 100%;
  background-color: $bg-color1;
  min-height: 100vh;
}
.status_bar {
  margin: 0 -30rpx;
  height: var(--status-bar-height);
  width: 750rpx;
}
.topWrap {
  position: relative;
  padding: 0 30rpx;
  display: flex;
  align-items: center;
  width: 750rpx;
  height: 88rpx;
  background: #292b2b;
  .arrow {
    position: absolute;
    left: 30rpx;
    // margin-right: 60rpx;
    width: 34rpx;
    height: 34rpx;
  }
  .text {
    flex: 1;
    // width: 136rpx;
    height: 48rpx;
    font-size: 34rpx;
    font-weight: 500;
    color: #ffffff;
    line-height: 48rpx;
    text-align: center;
  }
  .right {
    position: absolute;
    right: 30rpx;
    // width: 112rpx;
    height: 40rpx;
    font-size: 28rpx;
    font-weight: 400;
    color: #ffffff;
    line-height: 40rpx;
  }
}
.have {
  padding: 0 30rpx;
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 750rpx;
  height: 96rpx;
  background: #292b2b;
  .have_left {
    // width: 140rpx;
    height: 40rpx;
    font-size: 28rpx;
    font-weight: 400;
    color: #ffffff;
    line-height: 40rpx;
  }
  .highlight {
    color: #1fe6e6;
  }
  .have_right {
    width: 192rpx;
    height: 68rpx;
    background: linear-gradient(90deg, #1fe6e6 0%, #3f9ed2 48%, #df7fd6 100%);
    border-radius: 34rpx;
    text-align: center;
    font-size: 28rpx;
    font-weight: 400;
    color: #ffffff;
    line-height: 68rpx;
  }
}
.record_wrapper {
  padding: 30rpx;
  width: 750rpx;
}
.record {
  display: flex;
  align-items: center;
  width: 690rpx;
  height: 242rpx;
  //   border-radius: 24rpx;

  background-image: url(../../static/transaction_record_bg.png);
  background-repeat: no-repeat;
  background-size: 100% 242rpx;
  &_image {
    width: 242rpx;
    height: 242rpx;
    // border-radius: 24rpx;
  }
  &_content {
    flex: 1;
    padding: 30rpx;
    &_title {
      height: 44rpx;
      font-size: 32rpx;
      font-weight: 500;
      color: $text-color1;
      line-height: 44rpx;
      overflow: hidden;
      -webkit-line-clamp: 1;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-box-orient: vertical;
    }
    &_second {
      width: 388rpx;
      position: relative;
      margin-top: 20rpx;
      display: flex;
      align-items: center;
      // .integral {
      //   position: absolute;
      //   right: 0;
      //   height: 40rpx;
      //   font-size: 28rpx;
      //   font-weight: 500;
      //   color: #1fe6e6;
      //   line-height: 40rpx;
      // }
      .integral {
        text-align: right;
        height: 40rpx;
        font-size: 28rpx;
        font-weight: 500;
        color: #1fe6e6;
        line-height: 40rpx;
      }
    }
    &_avatar {
      width: 36rpx;
      height: 36rpx;
      border-radius: 50%;
    }
    &_username {
      flex: 1;
      margin-left: 8rpx;
      height: 36rpx;
      font-size: 26rpx;
      font-weight: 500;
      color: $text-color1;
      line-height: 36rpx;

      // max-width: 300rpx;
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
    }
    &_third {
      display: flex;
      align-items: center;
      justify-content: space-between;
      margin-top: 40rpx;
    }
    &_price {
      height: 42rpx;
      font-size: 36rpx;
      font-family: SFPro-Bold, SFPro;
      font-weight: bold;
      color: $text-color1;
      line-height: 42rpx;
    }
    &_status {
      height: 34rpx;
      font-size: 24rpx;
      font-weight: 400;
      color: #39a2ff;
      line-height: 34rpx;
    }
    &_CollectionCode {
      padding: 0 20rpx 0 30rpx;
      display: inline-block;

      margin-top: 40rpx;
      position: relative;
      left: 16rpx;
      // width: 330rpx;
      height: 34rpx;
      color: #ffffff;
      background: $gradient1;
      border-radius: 6rpx;

      font-size: 24rpx;
      font-weight: 400;
      line-height: 34rpx;
      text-align: center;

      height: 32rpx;
    }
    &_CollectionIcon {
      position: absolute;
      top: -10rpx;
      left: -26rpx;
      width: 52rpx;
      height: 52rpx;
    }
    &_no {
      display: inline-block;
      max-width: 300rpx;
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
    }
  }
}
.record + .record {
  margin-top: 30rpx;
}
.main {
  margin: 0 -30rpx;
  padding: 0 30rpx;
  height: 412rpx;
  background-image: url(../../static/integral_bg.png);
  background-repeat: no-repeat;
  background-size: 100%;
  &_top {
    margin-left: -30rpx;
    position: relative;
    // display: flex;

    width: 750rpx;
    height: 88rpx;
    text-align: center;
    &_img {
      position: absolute;
      left: 30rpx;
      top: 23rpx;
      width: 42rpx;
      height: 42rpx;
    }
    &_text {
      margin: 0 auto;
      // width: 68rpx;
      height: 88rpx;
      font-size: 34rpx;
      font-weight: 500;
      color: #ffffff;
      line-height: 88rpx;
    }
    &_right {
      position: absolute;
      top: 24rpx;
      right: 30rpx;
      // width: 112rpx;
      height: 40rpx;
      font-size: 28rpx;
      font-weight: 400;
      color: #ffffff;
      line-height: 40rpx;
    }
  }
  &_price {
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 30rpx auto 0;
    // width: 128rpx;
    height: 44rpx;
    font-size: 32rx;
    font-weight: 400;
    color: #ffffff;
    line-height: 44rpx;
    text-align: center;
    &_img {
      margin-right: 14rpx;
      width: 32rpx;
      height: 32rpx;
    }
  }
  &_num {
    margin-top: 14rpx;
    // width: 204rpx;
    height: 86rpx;
    // font-size: 44rpx;
    font-size: 72rpx;
    font-weight: bold;
    color: #ffffff;
    line-height: 86rpx;
    text-align: center;
  }
  &_notice {
    margin-top: 10rpx;
    // width: 174rpx;
    height: 34rpx;
    font-size: 24rpx;
    font-weight: 400;
    color: #ffffff;
    line-height: 34rpx;
    text-align: center;
  }
  &_line {
    margin-top: 40rpx;
    width: 750rpx;
    height: 2rpx;
    background: #d8d8d8;
    opacity: 0.18;
  }
  &_bottom {
    // padding: 28rpx 0 0 0;
    margin: 0 -30rpx;
    height: 104rpx;
    // padding: 24rpx 2rpx 0 2rpx;
    padding: 0 2rpx 0 2rpx;
    display: flex;
    align-items: center;
    background: #292b2b;
    border-top: 2rpx solid #313535;
  }
  &_item {
    // padding: 0 48rpx;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    // text-align: center;
    &_img {
      width: 32rpx;
      height: 32rpx;
    }
    &_text {
      margin-left: 6rpx;
      // width: 56rpx;
      height: 40rpx;
      font-size: 28rpx;
      font-weight: 400;
      color: #cccccc;
      line-height: 40rpx;
    }
    &_active {
      color: $text-color3;
    }
  }
  &_item:not(:first-child) {
    border-left: 2rpx solid #404040;
  }
}
</style>